package tgc.edu.tms.web.controller;

import java.util.HashSet;

import org.abyss.data.specifications.Rule;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import tgc.edu.tms.custom.CommonController;
import tgc.edu.tms.entity.Jcb;
import tgc.edu.tms.web.form.JcbForm;

@Controller
@RequestMapping(value = "/dictionary/jcb")
public class JcbController extends CommonController<Jcb, Integer, JcbForm>{

	@Override
	public Specification<Jcb> buildSpec(JcbForm form) {
		HashSet<Rule> rules=new HashSet<>();
		String xq = form.getXq();
		if(StringUtils.hasText(xq)) {
			rules.add(Rule.property("xq").contain(xq));
		}
		String jcsj = form.getJcsj();
		if(StringUtils.hasText(jcsj)) {
			rules.add(Rule.property("jcsj").contain(jcsj));
		}
		String search = form.getSearch();
		if(StringUtils.hasText(search)) {
			HashSet<Rule> rules2=new HashSet<>();
			rules2.add(Rule.property("xq").contain(search));
			rules2.add(Rule.property("jcsj").contain(search));
			rules.add(Rule.or(rules2));
		}
		return Rule.and(rules).toSpecification();
	}
 
	
}
